/**
 * 
 */
package org.framework2.test.webserver.http.response;

import java.io.IOException;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;

import com.sun.net.httpserver.HttpExchange;

/**
 * <p>
 * 测试桩HTTP回执响应处理器
 * </p>
 * @see 
 * @author ahli
 * @version WebServerTestMockV1, 2010-8-19
 * @since WebServerTestMockV1
 */
public class WSTMHttpResponse extends AbstractWSTMHttpResponse {

	private final HttpExchange httpExchange;
	
	private int status = 200;
	
	public WSTMHttpResponse(HttpExchange httpExchange){
		this.httpExchange = httpExchange;
	}
	
	@Override
	public PrintWriter getWriter() throws IOException {
		PrintWriter pw = new PrintWriter(new OutputStreamWriter(httpExchange.getResponseBody(), "UTF-8"));
		return pw;
	}
	
	@Override
	public void setStatus(int arg0) {
		this.status = arg0;
	}

	public int getStatus() {
		return status;
	}

	public OutputStream getOutputStream2() {
		return httpExchange.getResponseBody();
	}

	@Override
	public void write(String content) {
		try {
			httpExchange.getResponseBody().write(content.getBytes("UTF-8"));
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}
